<template>
	<view>
		<view class="search">
			<u--input placeholder="马卡龙色 多功能早餐机" v-model="form.keyword" class="search_input" border="surround"
				style="width:200rpx;" clearable></u--input>
			<u-button class="search_btn" color="#c55a5c" @click="handleSearch">
				<u-icon name="search" color="#fff" size="28"></u-icon>
			</u-button>
		</view>
		<view class="tabs">
			<u-tabs :list="list" lineWidth="0" activeStyle="color:#c55a5c;" :current="tab" :scrollable="false"
				@change="handleTebs">
			</u-tabs>
		</view>
		<view class="info">
			<view class="store" v-for="item in search_product" @click="handleDetail(item.id)">
				<image :src="item.image" mode=""></image>
				<view class="store_detail">
					<view style="font-size: 26rpx;">{{item.store_name}}</view>
					<view class="num">
						<view style="color: #999;font-size: 28rpx;">已售：{{item.sales}}</view>
					</view>
					<view style="font-size: 24rpx;color: #c55a5c;">￥{{item.price}}</view>
				</view>
				<view style="clear: both;"></view>
			</view>
		</view>
		<view class="wrap">
			<u-back-top :scrollTop="scrollTop" :iconStyle="iconStyle"></u-back-top>
		</view>
	</view>
</template>

<script>
	import { category } from '@/api'
	export default {
		data() {
			return {
				list: [{
					name: '综合',
				}, {
					name: '价格',
				}, {
					name: '销量'
				}, {
					name: '新品'
				}],
				form: {
					sid: '',
					keyword: this.$route.query.search_name,
					priceOrder: '',
					salesOrder: '',
					// 是否新品
					news: 0,
					page: 1,
					limit: 20,
					cid: 0,
				},
				tab: 0,
				scrollTop: 0,
				mode: 'square',
				iconStyle: {
					fontSize: '32rpx',
					color: '#fff'
				},
				sid: '',
				search_product: [],
			}
		},
		methods: {
			onPageScroll(e) {
				this.scrollTop = e.scrollTop;
			},
			async load_cate() {
				this.form.sid = this.sid
				let { msg, data, status } = await category.cate_product({ ...this.form })
				if (status) {
					this.search_product = data
				}
			},
			// 切换tab栏
			handleTebs(item) {
				if (item.name == '价格') {
					this.form.priceOrder = 'asc'
					this.load_cate()
				}
				if (item.name == '销量') {
					this.form.salesOrder = 'asc'
					this.load_cate()
				}
				if (item.name == '新品') {
					this.form.news = '1'
					this.load_cate()
				}
			},
			// 点击 查看每个商品的详情
			handleDetail(uid) {
				uni.navigateTo({
					url: `/pages/selection/detail/detail?uid=${uid}`
				});
			},
			// 搜索商品
			handleSearch() {
				this.load_cate()
			}
		},
		created() {
			this.load_cate()
			console.log(this.$route);
		},
		onLoad: function(option) {
			this.sid = option.sid
		}
	}
</script>

<style lang="scss">
	.search {
		display: flex;
		justify-content: space-between;
		padding: 18rpx 21rpx 26rpx 20rpx;

	}

	.search.search_input {
		width: 50rpx;
	}

	.search_btn {
		width: 78rpx;
		height: 67rpx;
		margin-left: 25rpx;
	}

	.info {
		border-top: 1px solid #ddd;
	}

	.store {
		background-color: #fff;
		padding: 34rpx 30rpx 36rpx 26rpx;
		margin-bottom: 35rpx;

		image {
			width: 201rpx;
			height: 190rpx;
			margin-right: 24rpx;
			float: left;

		}

		.store_detail {
			padding-top: 7rpx;
			padding-bottom: 17rpx;
			border-bottom: 1px solid #ddd;
			display: flex;
			flex-wrap: wrap;
			flex-direction: column;
		}

		.num {
			margin-top: 29rpx;
			margin-bottom: 41rpx;

			text {
				font-size: 26rpx;
				color: #999;
			}
		}
	}
</style>